package com.cj.core.crypto;

import cn.hutool.crypto.SecureUtil;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;

public class DigestUtil {

    /**
     * 普通的md5加密
     * */
    public static String md5(String content) {
        return SecureUtil.md5(content);
    }

    /**
     * md5加盐加密
     * */
    public static String md5(String content, String salt) {
        return SecureUtil.md5().setSalt(salt.getBytes()).digestHex(content);
    }

    /**
     * SHA-1加密
     * */
    public static String sha1(String content) throws Exception {
        return SecureUtil.sha1(content);
    }

    /**
     * SHA-1加密加盐
     * */
    public static String sha1(String content, String salt) throws Exception {
        return SecureUtil.sha1().setSalt(salt.getBytes()).digestHex(content);
    }

    /**
     * SHA-256加密
     * */
    public static String sha256(String text) throws Exception {
        return SecureUtil.sha256(text);
    }

    /**
     * SHA-256加密加盐
     * */
    public static String sha256(String text, String salt) throws Exception {
        return SecureUtil.sha256().setSalt(salt.getBytes()).digestHex(text);
    }

    // 示例用法
    public static void main(String[] args) throws Exception {
        String text = "Hello, Digest!";
        System.out.println("MD5: " + md5(text));
        System.out.println("SHA-1: " + sha1(text));
        System.out.println("SHA-256: " + sha256(text));

        // 文件摘要示例
        // System.out.println("File SHA-256: " + digestFile("path/to/file", "SHA-256"));
    }
}